import axios from 'axios'

console.log(123)
console.log(process.env.NODE_ENV)
// create an axios instance
const service = axios.create({
  // baseURL: 'http://localhost:3000', // url = base url + request url
  baseURL: process.env.NODE_ENV=== 'development' ? '/api':'/'
  // withCredentials: true, // send cookies when cross-domain requests
  // timeout: 5000 // request timeout
})

// request interceptor
service.interceptors.request.use(
  config => {
    // do something before request is sent
    return config
  },
  error => {
    // do something with request error
    console.log(error) // for debug
    return Promise.reject(error)
  }
)

// response interceptor
service.interceptors.response.use(
  response => {
    return response
  },
  error => {
   
    return Promise.reject(error)
  }
)

export default service
